package com.lei.sqlGoodsJsp.service.Impl;

import java.util.List;

import com.lei.sqlGoodsJsp.dao.LoginDao;
import com.lei.sqlGoodsJsp.dao.Impl.LoginDaoImpl;
import com.lei.sqlGoodsJsp.entity.LoginUserEntity;
import com.lei.sqlGoodsJsp.entity.Page;
import com.lei.sqlGoodsJsp.service.UserLoginServicePage;

public class UserLoginServicePageImpl implements UserLoginServicePage {
	private LoginDao loginDao = new LoginDaoImpl();

	@Override
	public void add(LoginUserEntity id) {
		loginDao.add(id);

	}

	@Override
	public List<LoginUserEntity> list() {

		return loginDao.listAll();
	}

	@Override
	public Page<LoginUserEntity> page(int currentPage, int pageSize) {
		int count = loginDao.getCount();
		List<LoginUserEntity> data = loginDao.getPage(currentPage, pageSize);
		int totalPage = count / pageSize;
		totalPage += count % pageSize == 0 ? 0 : 1;
		Page<LoginUserEntity> page = new Page<>(count, totalPage, currentPage, data);
		return page;
	}

	@Override
	public LoginUserEntity getById(Long id) {
		return loginDao.getById(id);
	}

}
